iT邦幫忙

0

【C#】Abstract Class vs Interface

c#
  • 分享至 

  • xImage
  •  

我們今天來看到抽象類別跟介面的差異性吧~


學習目標: Abstract Class and Interface的概念及實務

學習難度: ☆☆☆


https://ithelp.ithome.com.tw/upload/images/20220409/201478869ffhKOsjQn.png


抽象類別是怎麼被實現的呢~

    public abstract class Programmer
    {
        public string name { get; set; }

        public abstract void coding();

        public virtual void debug()
        {
            Console.WriteLine("I could debug");
        }
    }

    public class UnityProgrammer:Programmer
    {
        public override void coding()
        {
            Console.WriteLine("I could used unity to develop game");
        }
    }

介面是怎麼被實現的呢~

    public interface IProgrammer
    {
        public string name { get; set; }

        public void coding();
    }

    public class UnityProgrammer: IProgrammer
    {
        public string name { get; set; }

        public void coding()
        {
            Console.WriteLine("I could used unity to develop game");
        }
    }

參考資料:

https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-c-sharp/


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言